# -*- coding = utf-8 -*-
# @Time：2022/3/29 0:42
# @Author：3ic
# @File：iclogger.py
# @Software：PyCharm
import logging
import os
from pathlib import Path


class IcLogger(logging.Logger):
    def __init__(self, file_name):
        logging.Logger.__init__(self, name=file_name)
        if not os.path.exists(os.path.dirname(file_name)):
            os.makedirs(os.path.dirname(file_name))
        if not os.path.exists(file_name):
            Path(file_name).touch()
        formatter = logging.Formatter("%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s")
        fh = logging.FileHandler(file_name)
        fh.setLevel(logging.INFO)
        fh.setFormatter(formatter)
        sh = logging.StreamHandler()
        sh.setLevel(logging.INFO)
        sh.setFormatter(formatter)
        self.setLevel(logging.INFO)
        self.addHandler(fh)
        self.addHandler(sh)
